/*-----------------------------------------------------------------------------
* @Description:     登录首页
* @Version:         1.0.0
* @author:          zhangmengqi(1845955175@qq.com)
* @date             2017.11.5
* ==NOTES:=============================================
* v1.0.0(2017.11.5):
     初始生成
* ---------------------------------------------------------------------------*/
$(document).ready(function(){
    

    /**
     * 提交数据
     * @param  {[type]} ){                                   var                                    username      [description]
     * @param  {[type]} error: function      (message) {                   $("#modalDialog").modal( [description]
     * @return {[type]}        [description]
     */
    $('.J_submitBtn').click(function(){
        formValidatorAddForm();
        var data = $('#J_form').data('bootstrapValidator');
        if (data) {
            data.validate();
            if (!data.isValid()) {
                return false;
            }  else{
                send();
            }  
        }
        
    });
    function send(){
        var
            username = $('.J_username').val(),
            pwd = $('.J_pwd').val(),
            isRemenberMe = $('.J_remember').is(':checked') + 0,
            form = {
                username: username,
                password: pwd,
                isRemenberMe: isRemenberMe
            };

        $.ajax({
            type: jQuery.url.Login.getLogin.type,
            url: jQuery.url.Login.getLogin.url,
            contentType: "application/json; charset=utf-8",
            data: form,     //JSON.stringify
            dataType: "json",
            success: function (rs) {
                if(rs.code == 0){
                    location.reload();
                }else{
                    location.reload();
                }
            },
            error: function (message) {
                // alert("请求失败")
                Alert('提示信息', '操作失败，请重新操作!');
            }
        });
    }

    /**
     * 重置按钮清除校验
     */
    $(".J_resetBtn").click(function(){
        location.reload();
    });
    /*
     * 登录验证
     */ 
    function formValidatorAddForm(){
        $('#J_form').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                loginName: {
                    validators: {
                        notEmpty: {
                            message: '用户名不能为空，请重新输入'
                        }
                    }
                },
                pwd: {
                    validators: {
                        notEmpty: {
                            message: '密码不能为空，请重新输入'
                        }
                    }
                }
            }
        });
    }
});